import { wechatrequest } from './API/request'
import { getStorageSync } from '../crossplatform/apiservice/storage'

/**
 * 申请公司
 */
export const createCpRequest = ({ companyId, companyName, licenseUrl, tianyachaId, userId }) => {
  const landmark = getStorageSync('landmark')
  return wechatrequest.postparams('/orgCompany/create', {
    data: { companyName, licenseUrl, tianyachaId, applyAddress: landmark.landmarkName || '上海', companyId, userId }
  })
}

/**
 * 是否存在公司
 */
export const cpExistRequest = ({ name }) => {
  return wechatrequest.get('/orgCompany/name/exist', {
    data: { name }
  })
}

/**
 * 查询当前用户申请的公司
 */
export const applyCompany = ({ userId }) => {
  return wechatrequest.get('/orgCompany/my/apply', {
    data: { userId }
  })
}

/**
 * 查询当前用户所属的公司
 */
export const ownerCompany = () => {
  let userinfo = getStorageSync('userinfo')
  let openId = userinfo && userinfo.openId

  return wechatrequest.get('/orgCompany/owner', {
    data: { openId }
  })
}

/**
 * 切换当前用户所属的公司 TODO
 */
// export const changeDefault = ({ companyId }) => {
//   let userinfo = getStorageSync('userinfo')
//   let openId = userinfo && userinfo.openId
//   return wechatrequest.post('/orgCompany/change/default', {
//     data: { openId, companyId }
//   })
// }

/**
 * 切换当前用户所属的公司 TODO
 */
export const changeDefault = () => {
  return wechatrequest.post('@@/operator/operatorCenterInfo', {
    data: {}
  })
}

/**
 * 获取同事列表
 * */
export const getWorkmateList = () => {
  return wechatrequest.post('@@/operator/workmates', {
    data: {}
  })
}

/**
 * 查询企业主管理员信息
 * */
export const masterSearchRequest = () => {
  let userinfo = getStorageSync('userinfo')
  let companyId = userinfo && userinfo.companyId
  return wechatrequest.postparams('@@/operator/masterSearch', {
    data: { companyId }
  })
}

/**
 * 修改企业logo
 * */
export const changelogoRequest = ({ url }) => {
  let userinfo = getStorageSync('userinfo')
  let companyId = userinfo && userinfo.companyId
  return wechatrequest.postparams('/orgCompany/change/logo', {
    data: { url, companyId }
  })
}

/**
 * 申请者列表
 * */
export const operatorListEntryRequest = () => {
  let userinfo = getStorageSync('userinfo')
  let companyId = userinfo && userinfo.companyId
  return wechatrequest.postparams('@@/operator/applyComeInOperatorList', {
    data: { companyId }
  })
}

/**
 * 待解绑列表
 * */
export const orgOperatorreleaseRequest = () => {
  let userinfo = getStorageSync('userinfo')
  let companyId = userinfo && userinfo.companyId
  return wechatrequest.postparams('@@/operator/waitUnbindOperatorList', {
    data: { companyId }
  })
}

/**
 * 解绑通过不通过
 * */
export const orgOperatorhandlereleaseRequest = ({ userId, agree, operatorId }) => {
  return wechatrequest.get('/orgOperator/handle/release', {
    data: { userId, agree, operatorId }
  })
}

/**
 * 审核通过不通过
 * */
export const handleOperatorRequest = ({ userId, agree, operatorId }) => {
  return wechatrequest.postparams('/orgOperator/handle/operator', {
    data: { userId, agree, operatorId }
  })
}
